// license-header java merge-point
/**
 * This is only generated once! It will never be overwritten.
 * You can (and have to!) safely modify it by hand.
 * TEMPLATE:    SpringServiceImpl.vsl in andromda-spring cartridge
 * MODEL CLASS: AndroMDAModel::JR Appointment Service::com.systemsjr.jrappointment::invoice::service::InvoiceService
 * STEREOTYPE:  Service
 */
package com.systemsjr.jrenterprise.invoice.service;

import java.util.Collection;

import com.systemsjr.jrenterprise.invoice.Invoice;
import com.systemsjr.jrenterprise.invoice.vo.InvoiceSearchCriteria;
import com.systemsjr.jrenterprise.invoice.vo.InvoiceVO;

/**
 * @see com.systemsjr.jrappointment.invoice.service.InvoiceService
 */
public class InvoiceServiceImpl
    extends InvoiceServiceBase
{

    /**
     * @see com.systemsjr.jrappointment.invoice.service.InvoiceService#delete(InvoiceVO)
     */
    protected  void handleDelete(InvoiceVO invoiceVO)
        throws Exception
    {
        if(invoiceVO.getId() != null){
        	getInvoiceDao().remove(invoiceVO.getId());
        }
    }

    /**
     * @see com.systemsjr.jrappointment.invoice.service.InvoiceService#loadAll()
     */
    protected  Collection<InvoiceVO> handleLoadAll()
        throws Exception
    {
    	return getInvoiceDao().toInvoiceVOCollection(getInvoiceDao().loadAll());
    }

    /**
     * @see com.systemsjr.jrappointment.invoice.service.InvoiceService#save(InvoiceVO)
     */
    protected  InvoiceVO handleSave(InvoiceVO invoiceVO)
        throws Exception
    {
    	Invoice invoice = getInvoiceDao().invoiceVOToEntity(invoiceVO);
    	
    	if(invoiceVO.getId() == null){
    		invoice = getInvoiceDao().create(invoice);
    	} else{
    		getInvoiceDao().update(invoice);
    	}
    	
    	return getInvoiceDao().toInvoiceVO(invoice);
    }

    /**
     * @see com.systemsjr.jrappointment.invoice.service.InvoiceService#search(InvoiceSearchCriteria)
     */
    protected  Collection<InvoiceVO> handleSearch(InvoiceSearchCriteria searchCriteria)
        throws Exception
    {
    	return getInvoiceDao().toInvoiceVOCollection(getInvoiceDao().findByCriteria(searchCriteria));
    }

}